package com.hnx.admin.aurora.system.controller;

import com.hnx.admin.aurora.annotation.Log;
import com.hnx.admin.aurora.enums.BusinessType;
import com.hnx.admin.aurora.system.domain.param.sysConfig.form.SysConfigForm;
import com.hnx.admin.aurora.system.domain.param.sysConfig.query.SysConfigQuery;
import com.hnx.admin.aurora.system.service.SysConfigService;
import com.hnx.admin.aurora.utils.UUIDUtil;
import com.hnx.admin.aurora.web.json.ResultJson;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
项目名称： admin-aurora
创 建 人: 倔强的头发
创建日期： 2025/6/22   20:06:15 
描   述：
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/config")
public class SysConfigController {
    private final SysConfigService sysConfigService;
    /**
     * 根据参数编号获取详细信息
     */
    @PreAuthorize("@auth.hasPermi('system:config:query')")
    @GetMapping(value = "/{configId}")
    public ResultJson getInfo(@PathVariable String configId)
    {
        return sysConfigService.selectConfigById(configId);
    }
    /**
     * 根据参数键名查询参数值
     */
    @GetMapping(value = "/configKey/{configKey}")
    public ResultJson getConfigKey(@PathVariable String configKey)
    {
        String configValue = sysConfigService.selectConfigByKey(configKey);
        return ResultJson.data(configValue);
    }
    /**
     * 获取参数配置列表
     */
    @PreAuthorize("@auth.hasPermi('system:config:list')")
    @GetMapping("/list")
    public ResultJson list(SysConfigQuery config)
    {
        return sysConfigService.selectConfigList(config);
    }
    /**
     * 新增参数配置
     */
    @PreAuthorize("@auth.hasPermi('system:config:add')")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultJson add(@Validated @RequestBody SysConfigForm config)
    {
        config.setConfigId(UUIDUtil.getUUID());
        return sysConfigService.insertConfig(config);
    }
    /**
     * 删除参数配置
     */
    @PreAuthorize("@auth.hasPermi('system:config:remove')")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}")
    public ResultJson remove(@PathVariable String[] configIds)
    {
        return sysConfigService.deleteConfigByIds(configIds);
    }
    /**
     * 修改参数配置
     */
    @PreAuthorize("@auth.hasPermi('system:config:edit')")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultJson edit(@Validated @RequestBody SysConfigForm config)
    {
        return sysConfigService.updateConfig(config);
    }
    /**
     * 刷新参数缓存
     */
    @PreAuthorize("@auth.hasPermi('system:config:remove')")
    @Log(title = "参数管理", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public ResultJson refreshCache()
    {
        return sysConfigService.resetConfigCache();
    }
}
